package com.xframework.handler;

import com.xframework.Base;
import com.xframework.exception.BusinessException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by xuning on 2020/9/28.
 */
@ControllerAdvice
@ResponseBody
public class GlobalRestExceptionHandler {
    public GlobalRestExceptionHandler() {
        System.out.println("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx GlobalRestExceptionHandler xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
    }

    @ExceptionHandler(value = Exception.class)
    public String handle(Exception e) {
        return Base.DOUBLE_QUOTATION + new BusinessException(e).getMessage() + Base.DOUBLE_QUOTATION;
//        RespData respData = new RespData(0, e.getMessage());
//        return respData;
    }
}
